import mysql.connector


# 连接指定的数据库
mydb = mysql.connector.connect(
    host='localhost',
    user='root',
    password='',
    database=' mydatabase'
)

# 获取游标
cursor = mydb.cursor()

# 创建数据表
cursor.execute('DROP TABLE IF EXISTS `user`')
cursor.execute('''CREATE TABLE USER (
                    id INT PRIMARY KEY AUTO_INCREMENT,
                    NAME VARCHAR(10) UNIQUE,
                    age INT
                )''')

# 关闭
cursor.close()
mydb.close()